//
// Created by Administrator on 2023/11/21.
//
#include "iostream"
#include "algorithm"

using namespace std;
typedef pair<int, int> PII;

const int N = 5e4 + 10;
PII cow[N];

int main() {
    int n;
    cin >> n;
    int w, s;
    for (int i = 0; i < n; ++i) {
        cin >> w >> s;
        cow[i]={w+s,w};
    }
    sort(cow, cow + n);

    int res = -2e9, sum = 0;//sum为前边所有的重量
    for (int i = 0; i < n; ++i) {
        w=cow[i].second,s=cow[i].first-w;
        res=max(res,sum-s);
        sum+=w;
    }
    cout<<res;
}